#Boa:Frame:Frame_DataProcess

import wx,os
import wx.lib.buttons
from wx.lib.anchors import LayoutAnchors

def create(parent):
    return Frame_DataProcess(parent)

[wxID_FRAME_DATAPROCESS, wxID_FRAME_DATAPROCESSBITMAPBUTTON1, 
 wxID_FRAME_DATAPROCESSGAUGE1, wxID_FRAME_DATAPROCESSPANEL1, 
 wxID_FRAME_DATAPROCESSSTART, wxID_FRAME_DATAPROCESSSTATICTEXT1, 
 wxID_FRAME_DATAPROCESSSTATICTEXT2, wxID_FRAME_DATAPROCESSSTATUSBAR1, 
 wxID_FRAME_DATAPROCESSTEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(9)]

[wxID_FRAME_DATAPROCESSMENU1ITEMS0, wxID_FRAME_DATAPROCESSMENU1ITEMS1, 
 wxID_FRAME_DATAPROCESSMENU1ITEMS3, wxID_FRAME_DATAPROCESSMENU1ITEMS5, 
] = [wx.NewId() for _init_coll_menu1_Items in range(4)]

[wxID_FRAME_DATAPROCESSMENUFILEITEMS0, wxID_FRAME_DATAPROCESSMENUFILEITEMS1, 
 wxID_FRAME_DATAPROCESSMENUFILEITEMS3, wxID_FRAME_DATAPROCESSMENUFILEITEMS5, 
] = [wx.NewId() for _init_coll_menuFile_Items in range(4)]

[wxID_FRAME_DATAPROCESSMENUHELPITEMS0] = [wx.NewId() for _init_coll_menuHelp_Items in range(1)]

class Frame_DataProcess(wx.Frame):
    def _init_coll_menuBar1_Menus(self, parent):
        # generated method, don't edit

        parent.Append(menu=self.menuFile, title=u'File')
        parent.Append(menu=self.menuHelp, title=u'Help')

    def _init_coll_menuHelp_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_FRAME_DATAPROCESSMENUHELPITEMS0,
              kind=wx.ITEM_NORMAL, text=u'About')
        self.Bind(wx.EVT_MENU, self.OnAbout,
              id=wxID_FRAME_DATAPROCESSMENUHELPITEMS0)

    def _init_coll_menuFile_Items(self, parent):
        # generated method, don't edit

        parent.Append(help=u'Create a File',
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS0, kind=wx.ITEM_NORMAL,
              text=u'New')
        parent.Append(help=u'Open an exist File',
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS1, kind=wx.ITEM_NORMAL,
              text=u'Open')
        parent.AppendSeparator()
        parent.Append(help=u'Save File',
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS3, kind=wx.ITEM_NORMAL,
              text=u'Save')
        parent.AppendSeparator()
        parent.Append(help=u'Quit program',
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS5, kind=wx.ITEM_NORMAL,
              text=u'Exit')
        self.Bind(wx.EVT_MENU, self.OnSave,
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS3)
        self.Bind(wx.EVT_MENU, self.OnExit,
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS5)
        self.Bind(wx.EVT_MENU, self.OnOpenFile,
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS1)
        self.Bind(wx.EVT_MENU, self.OnNewFile,
              id=wxID_FRAME_DATAPROCESSMENUFILEITEMS0)

    def _init_utils(self):
        # generated method, don't edit
        self.menuFile = wx.Menu(title='')

        self.menuHelp = wx.Menu(title='')

        self.menuBar1 = wx.MenuBar()

        self._init_coll_menuFile_Items(self.menuFile)
        self._init_coll_menuHelp_Items(self.menuHelp)
        self._init_coll_menuBar1_Menus(self.menuBar1)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME_DATAPROCESS,
              name=u'Frame_DataProcess', parent=prnt, pos=wx.Point(440, 490),
              size=wx.Size(650, 377), style=wx.DEFAULT_FRAME_STYLE,
              title=u'DataProcess')
        self._init_utils()
        self.SetClientSize(wx.Size(642, 339))
        self.Show(True)
        self.SetMenuBar(self.menuBar1)

        self.statusBar1 = wx.StatusBar(id=wxID_FRAME_DATAPROCESSSTATUSBAR1,
              name='statusBar1', parent=self, style=0)
        self.statusBar1.SetAutoLayout(True)
        self.SetStatusBar(self.statusBar1)

        self.panel1 = wx.Panel(id=wxID_FRAME_DATAPROCESSPANEL1, name='panel1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(642, 297),
              style=wx.TAB_TRAVERSAL)
        self.panel1.SetForegroundColour(wx.Colour(0, 0, 255))

        self.staticText1 = wx.StaticText(id=wxID_FRAME_DATAPROCESSSTATICTEXT1,
              label=u'BHTC Data Process Tool', name='staticText1',
              parent=self.panel1, pos=wx.Point(144, 32), size=wx.Size(374, 42),
              style=0)
        self.staticText1.SetFont(wx.Font(26, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))
        self.staticText1.SetForegroundColour(wx.Colour(0, 0, 255))

        self.staticText2 = wx.StaticText(id=wxID_FRAME_DATAPROCESSSTATICTEXT2,
              label=u'BHTC File:', name='staticText2', parent=self.panel1,
              pos=wx.Point(24, 144), size=wx.Size(94, 24), style=0)
        self.staticText2.SetFont(wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME_DATAPROCESSTEXTCTRL1,
              name='textCtrl1', parent=self.panel1, pos=wx.Point(136, 144),
              size=wx.Size(392, 29), style=0,
              value=u'BHTC File You Want to Convert')
        self.textCtrl1.SetFont(wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.bitmapButton1 = wx.BitmapButton(bitmap=wx.Bitmap(u'D:/GUI/Open.bmp',
              wx.BITMAP_TYPE_BMP), id=wxID_FRAME_DATAPROCESSBITMAPBUTTON1,
              name='bitmapButton1', parent=self.panel1, pos=wx.Point(552, 144),
              size=wx.Size(48, 32), style=wx.BU_AUTODRAW)
        self.bitmapButton1.Bind(wx.EVT_BUTTON, self.OnOpenBHTCFile,
              id=wxID_FRAME_DATAPROCESSBITMAPBUTTON1)

        self.Start = wx.Button(id=wxID_FRAME_DATAPROCESSSTART, label=u'Start',
              name=u'Start', parent=self.panel1, pos=wx.Point(552, 144),
              size=wx.Size(56, 32), style=0)
        self.Start.Show(False)
        self.Start.SetFont(wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))
        self.Start.SetForegroundColour(wx.Colour(0, 0, 255))
        self.Start.Bind(wx.EVT_BUTTON, self.OnStartButton,
              id=wxID_FRAME_DATAPROCESSSTART)

        self.gauge1 = wx.Gauge(id=wxID_FRAME_DATAPROCESSGAUGE1, name='gauge1',
              parent=self.panel1, pos=wx.Point(56, 224), range=100,
              size=wx.Size(528, 28), style=wx.GA_HORIZONTAL)
        self.gauge1.SetShadowWidth(5)
        self.gauge1.SetBezelFace(5)
        self.gauge1.Bind(wx.EVT_IDLE, self.IdleHandler)
        self.gauge1.Show(False)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.count=0
        

    def OnSave(self, event):
        dlg = wx.FileDialog(
            self, message="Save file as ...", defaultDir=os.getcwd(), 
            defaultFile="", wildcard="*.*", style=wx.SAVE
            )

        # This sets the default filter that the user will initially see. Otherwise,
        # the first filter in the list will be used by default.
        dlg.SetFilterIndex(4)

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            
            # The code to do so would be similar to this, assuming 'data' contains
            # the data you want to save:
            #
            fp = file(path, 'w') # Create file anew
            fp.write("data")
            fp.close()
            #
            # You might want to add some error checking :-)
            #

        
        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()

    def OnExit(self, event):
        event.Skip()

    def OnOpenFile(self, event):
        dlg = wx.FileDialog(
            self, message="Choose a file", defaultDir=os.getcwd(), 
            defaultFile="", wildcard="*.*", style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            paths = dlg.GetPath()
        
        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()
    def OnNewFile(self, event):
        event.Skip()

    def OnAbout(self, event):
        wx.MessageBox("This is a wxPython hello world sample",
                      "About Hello world",wx.OK|wx.ICON_INFORMATION,self)

    def OnOpenBHTCFile(self, event):
        dlg = wx.FileDialog(
            self, message="Choose a file", defaultDir=os.getcwd(), 
            defaultFile="", wildcard="*.*", style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )

        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            paths = dlg.GetPath()
            self.textCtrl1.SetValue(paths)
            self.bitmapButton1.Show(False)
            self.Start.Show(True)
        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()

    def OnStartButton(self, event):
        self.gauge1.Show(True)
        self.gauge1.SetValue(0)
        IdleHandler()
        #for Index in 100:
        #    self.gauge1.SetValue(Index)

    def IdleHandler(self, event):
        
        self.count = self.count + 0.5
       
        
        self.gauge1.SetValue(self.count)
    

    
        
